import router from '@/router'
import userProfileService from '@/service/userProfileService'
import { FUNC_OPEN_TYPE } from '@/constants/layout'
import { ROUTES, ROUTE_NAMES } from '@/constants/routes'

export const navigateToMenu = (functionId) => {
    const currentRoute = router.currentRoute.value

    const query = {
        ...currentRoute.query,
        fid: functionId
    }

    router.push({
        path: ROUTES.RENDER,
        name: ROUTE_NAMES.PC_RENDER,
        query: query
    })
}
export const navigateToMenuByConfig = (functionId) => {
    const funcOpenMode = userProfileService.getUserProfile("wrp_funcOpenMode")
    if (funcOpenMode === FUNC_OPEN_TYPE.NEWTAB) {
        navigateInNewTab(functionId)
        return
    }
    navigateToMenu(functionId)
}
export const navigateInNewTab = (functionId) => {
    const currentRoute = router.currentRoute.value

    const query = {
        ...currentRoute.query,
        fid: functionId
    }

    // 构建查询字符串
    const queryString = new URLSearchParams(query).toString()

    // 构建完整的URL
    const baseUrl = window.location.origin + ROUTES.HARDCODE_WEB_RENDER
    const newUrl = `${baseUrl}?${queryString}`

    // 在新标签页中打开
    window.open(newUrl, '_blank')
}

